package ch.sfug.util {
	import flash.utils.getTimer;
	
	import ch.sfug.log.Logger;	

	/**
	 * @author loop
	 */
	public class Profiler {

		private static var files:Object = new Object();

		/**
		 * starts the profilling with the given name
		 */
		public static function start( name:String ):void {
			files[ name ] = getTimer();
		}

		
		/**
		 * starts to profile
		 */
		public static function stop( name:String ):void {
			var found:Boolean = false;
			for (var i:String in files) {
				if( i == name ) {
					Logger.log("Profiler task (" + i + "): " + ( getTimer() - files[ i ] ) + "ms");
					found = true;
					break;
				}
			}
			if( !found ) throw new Error("could not found profiler task to stop with name: " + name);
		}
	}
}
